!****************************
MODULE ElliDef
!***************************

IMPLICIT NONE
SAVE
PRIVATE
INTEGER, PUBLIC, PARAMETER :: NM=0,DR=1
INTEGER, PUBLIC, PARAMETER :: Precision=SELECTED_REAL_KIND(14,32),InternalBC=999, &
     CSR_LAPL=7,CSR_PRECOND=8 ! last two refer to where the operators are
REAL (KIND=Precision), PUBLIC, PARAMETER :: zero=0.0D0,one=1.0d0
TYPE, PUBLIC :: BC
   INTEGER :: bc_type
   REAL (KIND=Precision), POINTER, DIMENSION (:,:) :: p=>NULL()
END TYPE BC
TYPE,PUBLIC :: CRS ! COMPACT ROW STORAGE structure
   INTEGER :: nNonZeros ! rather unhappy name. 
                        !it is in fact the number of columns of the matrix
   REAL (KIND=Precision), POINTER, DIMENSION (:) :: rValues =>NULL() 
   INTEGER,  POINTER, DIMENSION (:) :: columns=>NULL(),rowIndex=>NULL()
END TYPE CRS
TYPE, PUBLIC :: DIA ! Diagonal compact storage
   INTEGER :: ncol ! nrows is given by the SIZE(rValues,1)
                   ! 
   REAL (KIND=Precision),  DIMENSION (:,:),POINTER :: rValues=>NULL()
   INTEGER, DIMENSION (:), POINTER :: distance=>NULL()
END TYPE DIA

TYPE, PUBLIC :: M_P
   TYPE (CRS), POINTER :: crsptr=>NULL()
   TYPE (DIA), POINTER :: diaptr=>NULL()
END TYPE M_P

TYPE :: IT
   INTEGER :: lfil  ! infil of LU precond
   REAL (KIND=Precision) :: droptol ! tol used for LU precond
   REAL (KIND=Precision), DIMENSION (:), POINTER :: fpar=>NULL()
   INTEGER, DIMENSION (:), POINTER :: perm=>NULL()
   INTEGER, DIMENSION (:), POINTER :: ipar_pd=>NULL(),ipar_it=>NULL()
   TYPE (CRS) :: G
END TYPE IT


TYPE, PUBLIC :: Elli

   INTEGER :: mX(3),mthbc(6)
   REAL (KIND=Precision) :: dX(3)

   TYPE (M_P), POINTER,  DIMENSION (:) :: G => NULL()
   TYPE (BC), POINTER, DIMENSION (:) :: bc => NULL()
   TYPE (IT) :: it
   INTEGER (KIND=INT_PTR_KIND()), POINTER, DIMENSION (:) :: pt => NULL()
   INTEGER (KIND=INT_PTR_KIND()), POINTER, DIMENSION (:) :: ptprcond => NULL()
!   INTEGER (KIND=4), POINTER, DIMENSION (:) :: pt => NULL()
   REAL (KIND=Precision), POINTER, DIMENSION (:,:,:) :: div,p,pold,diag
   REAL (KIND=Precision), POINTER, DIMENSION (:,:,:,:) :: qe
   INTEGER :: ndim
END TYPE Elli

END MODULE ElliDef

   
   
